package indexingSystem;

import java.io.PrintStream;
import java.util.Vector;
import java.util.regex.Pattern;

public class IndexingSystem {
	private static Pattern filter = Pattern.compile("[\\s\\p{Punct}\\p{Cntrl}\\d]+");
	private static IndexingDatabase db = null;
	private static Clusters clusters = new Clusters();
	private static PrintStream printStream = new PrintStream(System.out);
	public static void initialize(String url, String user, String passwd) throws Exception {
		if (db == null) {
			IndexingDatabase.setURL(url);
			IndexingDatabase.setUser(user);
			IndexingDatabase.setPassword(passwd);
			db = IndexingDatabase.getInterface();					
		}
	}
	public static PrintStream getPrintStream(){
			return printStream;
	}
	public static void setDictionary(ClusterDictionary dict) throws Exception {
		clusters.setDictionary(dict);
	}
	public static Vector<Document> documents(){
		return clusters.documents();
	}
	public static Pattern getFilter() {
		return filter;
	}
	public static void addDocument(Document document) throws Exception {
		clusters.addDocument(document);
	}
	public static void commit() throws Exception {
		clusters.distribute();
	}
	public static void halt() throws Exception {
		db.close();
	}
	public static Clusters getClusters(){
		return clusters;
	}
}
